package proxy.example.dynamic;

import proxy.example.GiveGift;
import proxy.example.Pursuit;
import proxy.example.SchoolGirl;

/**
 * @author Chen Guang
 * @date 2019/3/29 0029 下午 16:35
 */
public class Test {
    public static void main(String[] args) {

        System.out.println("---- jdk ----- 实现");
        SchoolGirl jiaojiao = new SchoolGirl("李建刚");
        GiveGift proxy = (GiveGift) new JdkProxyFactory(new Pursuit(jiaojiao)).getProxyInstance();

        System.out.println(proxy.getClass());
        //class com.sun.proxy.$Proxy0

        proxy.giveChocolate();
        proxy.giveDolls();
        proxy.giveFlowers();

        System.out.println("---- Cglib ----- 实现");
        SchoolGirl girl = new SchoolGirl("赵铁柱");
        GiveGift giveGift = (GiveGift) new CglibProxyFactory(new Pursuit(girl)).getProxyInstance();

        System.out.println(giveGift.getClass());
        //class proxy.example.Pursuit$$EnhancerByCGLIB$$54e8265e

        giveGift.giveChocolate();
        giveGift.giveDolls();
        giveGift.giveFlowers();
    }
}
